package org.linlinjava.litemall.admin.controller;

import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.dto.LumiereLevelMemberDto;
import org.linlinjava.litemall.admin.service.AdminLumiereLevelMemberService;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 管理卢米埃级成员控制器
 * 积分兑换
 *
 * @author yliyun
 * @date 2022/09/14
 */
@RestController
@RequestMapping("/admin/levelMember")
@Validated
public class AdminLumiereLevelMemberController {
    /**
     * 卢米埃级别会员服务
     */
    @Autowired
    private AdminLumiereLevelMemberService lumiereLevelMemberService;


    /**
     * 列表
     * 查询等级会员种类
     *
     * @param levelMemberName 级成员名
     * @param page            页面
     * @param limit           限制
     * @param sort            排序
     * @param order           订单
     * @return {@link Object}
     */
    @GetMapping("list")
    @LogAnno
    public Object list(String levelMemberName,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order){
        return lumiereLevelMemberService.list(levelMemberName,page,limit,sort,order);
    }

    /**
     * 添加
     * 添加等级会员
     *
     * @param dto dto
     * @return {@link Object}
     */
    @PutMapping("add")
    @LogAnno
    @Transactional
    public Object add(@RequestBody LumiereLevelMemberDto dto){
        return lumiereLevelMemberService.add(dto);
    }

    /**
     * 查询会员没有孩子
     * 查询没有下一级的等级会员
     *
     * @return {@link Object}
     */
    @GetMapping("queryMemberNoChildren")
    @LogAnno
    public Object queryMemberNoChildren(){
        return lumiereLevelMemberService.queryMemberNoChildren();
    }

    /**
     * 更新
     * 更改等级会员
     *
     * @param dto dto
     * @return {@link Object}
     */
    @PutMapping("update")
    @LogAnno
    public Object update(@RequestBody LumiereLevelMemberDto dto){
        return lumiereLevelMemberService.update(dto);
    }

    /**
     * 细节
     * 会员详情
     *
     * @param memberId 成员身份
     * @return {@link Object}
     */
    @GetMapping("detail")
    @LogAnno
    public Object detail(@RequestParam Integer memberId){
       return  lumiereLevelMemberService.detail(memberId);
    }

    /**
     * 更新状态
     * 更改等级会员
     *
     * @param memberId 成员身份
     * @return {@link Object}
     */
    @PutMapping("updateStatus")
    @LogAnno
    public Object updateStatus(@RequestParam Integer memberId){

        return lumiereLevelMemberService.updateStatus(memberId);
    }

    /**
     * 删除
     *
     * @param memberId 成员身份
     * @return {@link Object}
     */
    @DeleteMapping("delete")
    @LogAnno
    public Object delete(@RequestParam Integer memberId){
        return lumiereLevelMemberService.delete(memberId);
    }



}
